minify-js
Extremely fast JavaScript minifier, written in Rust.
Goals
- Fully written in Rust for maximum compatibility with Rust programs and derivatives (FFI, WASM, embedded, etc.).
- Maximises performance on a single CPU core for simple efficient scaling and easy compatible integration.
- Minification of individual inputs/files only; no bundling or transforming.
- Prefer minimal complexity and faster performance over maximum configurability and minimal extra compression.
Performance
Comparison with esbuild, run on common libraries.
Features
- Fast parsing powered by SIMD instructions and lookup tables.
- Minification of identifiers.
- Omits semicolons, spaces, parentheses, and braces where possible.
Usage
CLI
Precompiled binaries are available for Linux, macOS, and Windows.
Linux x64 | macOS x64 | Windows x64
Use the --help
argument for more details.
Rust
Add the dependency:
[]
= "0.1.5"
Call the method:
use minify;
let mut code: & = b"let x = 1;";
let mut out = Vec new;
minify.unwrap;
assert_eq!;
Node.js
Install the dependency:
Call the method:
import {minify} from "@minify-js/node";
const src = Buffer.from("let x = 1;", "utf-8");
const min = minify(src);
In progress
- Combine and reorder declarations.
- Minify import and export syntax.
- More extensive testing, especially over rare syntax.
- Evaluation and folding of constant expressions.
- Parse and erase TypeScript syntax.
- FFI libraries for other languages.
- Aliasing of reused well-knowns.
- Removal of unreachable, unused, and redundant code.
- Inlining single-use declarations.
- Aliasing frequently accessed properties and called methods.
- Better support for non-ASCII identifiers.
- Replacing if statements with conditional and logical expressions.
- Aliasing repeated identical literal values.
- Micro-optimisations:
- Unwrap string literal computed members, then identifier or number string members.
- Replace
x === null || x === undefined
withx == null
, wherex
is side-effect free. - Replace
typeof x === "undefined"
withx === undefined
. - Using shorthand properties and Object.assign.
- (Dangerous) Replace functions without use of
this
with arrow functions. - Replace
void x
withundefined
, wherex
is side-effect free. - Replace
return undefined
withreturn
. - Replace
const
withlet
. - Hoist
let
andconst
. - Unwrapping blocks.
- Unwrapping paretheses, altering expressions as necessary.
- Replace
typeof
andinstanceof
with functions. if (...) return a; else if (...) return b; else return c
=>return (...) ? a : (...) ? b : c
.